/**
 * Author: grx
 * Description: 学习模块中子功能Fragment的适配器类
 */
package com.example.parallelandroid;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import java.util.List;

public class StudyFragmentAdapter extends FragmentStateAdapter {

    private List<Fragment> fragments;

    public StudyFragmentAdapter(List<Fragment> fragments, @NonNull FragmentActivity fragmentActivity) {
        super(fragmentActivity);
        this.fragments = fragments;
    }

    @NonNull
    @Override
    public Fragment createFragment(int position) {
        if (fragments != null) {
            return fragments.get(position);
        }
        return null;
    }

    @Override
    public int getItemCount() {
        if (fragments != null) {
            return fragments.size();
        }
        return 0;
    }
}
